package com.Action;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;











import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.Bean.wdhtcustomerModel;
import com.Bean.wdhtroomModel;
import com.Bean.wdreceptionrecordModel;
import com.Service.wdcustomerService;
@Controller

public class wdcustomerAction {
@Autowired
	private wdcustomerService  wdcustomerService ;
    
    @RequestMapping("/selectAllCustomer.do")
    public String list(Model model,wdhtcustomerModel wbean){
    	 wbean.setDeleteState("1");
    	 System.out.println(wbean.getCustomerName());
    	 if("".equals(wbean.getCustomerName())){
    		 wbean.setCustomerName(null);
    	 }
	    List<wdhtcustomerModel> list  = wdcustomerService.getList(wbean);
	    model.addAttribute("list", list);
    	return "OrganizationsManager";	
    }
    
   @ RequestMapping("/addcustomer.do")
   public String addcustomer(wdhtcustomerModel wbean){
	   wbean.setDeleteState("1");
	   wbean.setDeleteUser("未记录");
	   int i = wdcustomerService.insert(wbean);
	   return "redirect:selectAllCustomer.do";
   }
   
   @RequestMapping("/deletecustomer.do")
   public String deletecustomer(String customerId,wdhtcustomerModel wbean){
	   
	 //  int i = wdcustomerService.deleteByPrimaryKey(customerId);
	   wbean.setCustomerId(customerId);
	   wbean.setDeleteState("0");
	   int i = wdcustomerService.updatecustomer(wbean);
		System.out.println();
		return "redirect:selectAllCustomer.do";
   }
 
   @RequestMapping("/updatecustomer.do")
   public String updatecustomer(Model model,wdhtcustomerModel wbean){
	   String customerId = wbean.getCustomerId();
	   wdhtcustomerModel wcbean = wdcustomerService.updateselectcustomer(customerId);
	   model.addAttribute("wbean", wcbean);
	   return "updateCustomer";  
   }
   
   @RequestMapping("addupdatecustomer.do")
   public String updateaddcustomer(wdhtcustomerModel wbean) throws ParseException{
	   SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
	   System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
	   java.util.Date date=df.parse(df.format(new Date())); 
	   System.out.println("====================="+date);
	   wbean.setUpdateTime(date);
		int i = wdcustomerService.updatecustomerupdate(wbean);
		//System.out.println("==============================="+i);
	    return "redirect:selectAllCustomer.do";
   }
   
   
   //客户记录添加
   
   @RequestMapping("//selectrecord.do")
   public String select(Model model,wdhtcustomerModel wbean){
	   String customerId = wbean.getCustomerId();
	   wdhtcustomerModel wcbean = wdcustomerService.updateselectcustomer(customerId);
	  
	   model.addAttribute("wbean", wcbean);
	   System.out.println(wcbean);
	   return "addrecored"; 
   }
   //表单验证
   @RequestMapping("SaleYanzheng.do")
   public @ResponseBody Map<String, Object> SaleYanzhengtoAjax(wdhtcustomerModel wbean){
		String customerName = wbean.getCustomerName();
		System.out.println("大家好"+customerName);
		wdhtcustomerModel cmbean = wdcustomerService.salectsaleyanzheng(customerName);
		  Map<String, Object> comMap = new HashMap<String, Object>();
		  comMap.put("customer", cmbean);
		  return comMap;
		}
   
   //
}
